package com.hkc.huakang.hkcpaperless;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class SettingActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_setting);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        EditText  ipTV=(EditText) findViewById(R.id.ip_tv);
        EditText  baseName=(EditText) findViewById(R.id.base_name);
        EditText  baseUserName=(EditText) findViewById(R.id.base_user_name);
        EditText basePass =(EditText) findViewById(R.id.base_user_pass);
         findViewById(R.id.close_im).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 SettingActivity.this.finish();
             }
         });
        findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                SharedPreferencesUtils.getInstance().saveMysqlIP(SettingActivity.this,ipTV.getText().toString());
                SharedPreferencesUtils.getInstance().saveDataName(SettingActivity.this,baseName.getText().toString());
                SharedPreferencesUtils.getInstance().saveMYSQL_UserNAME(SettingActivity.this,baseUserName.getText().toString());
                SharedPreferencesUtils.getInstance().saveMYSQL_PASS(SettingActivity.this, basePass.getText().toString());
                Toast.makeText(SettingActivity.this,"保存成功！",Toast.LENGTH_SHORT).show();
                SettingActivity.this.finish();
            }
        });
        ipTV.setText(SharedPreferencesUtils.getInstance().getMysqlIP(this));
        baseName.setText(SharedPreferencesUtils.getInstance().getDataName(this));
        baseUserName.setText(SharedPreferencesUtils.getInstance().getMYSQL_UserNAME(this));
        basePass.setText(SharedPreferencesUtils.getInstance().getMYSQL_PASS(this));
    }
}